const { createMoment, getMomentById, getMonmentList, updateMoment, deleteMoment } = require('../service/moment.service')
class MomentControll {
  async create(ctx, next) {
    const { name, id } = ctx.user
    // 1.获取用户及发布动态信息(user_id,content,图片。。。)
    const { content } = ctx.request.body
    // 2.将用户发布动态插入数据库
    const results = await createMoment(id, content)
    ctx.body = results
  }
  async momentDetail(ctx, next) {
    // 1.获取请求参数中的momentId
    const { momentId } = ctx.params
    // 2.获取对应评论
    const results = await getMomentById(momentId)
    ctx.body = results
  }
  async momentList(ctx, next) {
    //   1.获取用户数据偏移量
    const { offset, size } = ctx.request.query
    // 2.查询列表
    const results = await getMonmentList(offset, size)
    ctx.body = results
  }
  async updateMoment(ctx, next) {
    const { momentId } = ctx.params
    const { content } = ctx.request.body
    const { id, name } = ctx.user
    console.log(momentId, content, id, name)
    const results = await updateMoment(content, momentId)
    if (results) {
      ctx.body = '修改成功'
    } else {
      ctx.body = '修改失败'
    }
  }
  async deleteMomentById(ctx, next) {
    const { momentId } = ctx.params
    console.log(momentId)
    const results = await deleteMoment(momentId)
    if (results) {
        ctx.body = '删除成功'
      } else {
        ctx.body = '删除失败'
      }
  }
}
module.exports = new MomentControll()
